<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:r="clr-namespace:WPFExcelReport.Controls.TreeListViewControl"
    xmlns:s="clr-namespace:System;assembly=mscorlib"
    xmlns:mwt="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero">

  <r:LevelToIndentConverter x:Key="LevelToIndentConverter"/>

  
  <Style TargetType="{x:Type r:TreeListViewItem}">

    <Setter Property="FrameworkElement.FocusVisualStyle">
      <Setter.Value>
        <Style TargetType="IFrameworkInputElement">
          <Style.Resources>
            <ResourceDictionary />
          </Style.Resources>
          <Setter Property="Control.Template">
            <Setter.Value>
              <ControlTemplate>
                <Rectangle RadiusY="2" Stroke="#8E6EA6F5" RadiusX="2" StrokeThickness="1" />
              </ControlTemplate>
            </Setter.Value>
          </Setter>
        </Style>
      </Setter.Value>
    </Setter>
    <Setter Property="Panel.Background">
      <Setter.Value>
        <SolidColorBrush>#00FFFFFF</SolidColorBrush>
      </Setter.Value>
    </Setter>
    <Setter Property="Border.BorderBrush">
      <Setter.Value>
        <SolidColorBrush>#00FFFFFF</SolidColorBrush>
      </Setter.Value>
    </Setter>
    <Setter Property="Border.BorderThickness">
      <Setter.Value>
        <Thickness>1,1,1,1</Thickness>
      </Setter.Value>
    </Setter>
    <Setter Property="FrameworkElement.Margin">
      <Setter.Value>
        <Thickness>0,0,0,1</Thickness>
      </Setter.Value>
    </Setter>
    <Setter Property="Control.Padding">
      <Setter.Value>
        <Thickness>5,2,5,2</Thickness>
      </Setter.Value>
    </Setter>
    <Setter Property="Control.VerticalContentAlignment">
      <Setter.Value>
        <x:Static Member="VerticalAlignment.Center" />
      </Setter.Value>
    </Setter>
    <Setter Property="Control.Template">
      <Setter.Value>
        <ControlTemplate TargetType="r:TreeListViewItem">
          <Grid>
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
              <RowDefinition Height="Auto"/>
              <RowDefinition/>
            </Grid.RowDefinitions>

            <Border x:Name="item" BorderBrush="{TemplateBinding Border.BorderBrush}" CornerRadius="2,2,2,2" BorderThickness="{TemplateBinding Border.BorderThickness}" Background="{TemplateBinding Panel.Background}" SnapsToDevicePixels="True">
              <Border CornerRadius="1,1,1,1" BorderThickness="1,1,1,1" Name="InnerBorder">
                <Grid>
                  <Grid.RowDefinitions>
                    <RowDefinition MaxHeight="11" />
                    <RowDefinition />
                  </Grid.RowDefinitions>
                  <Rectangle Visibility="Collapsed" Fill="#75FFFFFF" Name="UpperHighlight" />
                  <r:TreeGridViewRowPresenter x:Name="PART_Header" Grid.RowSpan="2"
                    FirstColumnIndent="{Binding Level,Converter={StaticResource LevelToIndentConverter},RelativeSource={RelativeSource AncestorType={x:Type r:TreeListViewItem}},ConverterParameter=16}"
                    Content="{TemplateBinding Header}" 
                    Columns="{Binding Path=Columns,RelativeSource={RelativeSource AncestorType={x:Type r:TreeListView}}}">
                    <r:TreeGridViewRowPresenter.Expander>
                      <Grid>
                        <ToggleButton Height="16" Width="16" ClickMode="Press" Name="Expander" IsChecked="{Binding Path=IsExpanded,RelativeSource={RelativeSource AncestorType={x:Type r:TreeListViewItem}}}">
                          <ToggleButton.Style>
                            <Style TargetType="ToggleButton">
                              <Style.Resources>
                                <ResourceDictionary />
                              </Style.Resources>
                              <Setter Property="UIElement.Focusable">
                                <Setter.Value>
                                  <s:Boolean>False</s:Boolean>
                                </Setter.Value>
                              </Setter>
                              <Setter Property="FrameworkElement.Width">
                                <Setter.Value>
                                  <s:Double>16</s:Double>
                                </Setter.Value>
                              </Setter>
                              <Setter Property="FrameworkElement.Height">
                                <Setter.Value>
                                  <s:Double>16</s:Double>
                                </Setter.Value>
                              </Setter>
                              <Setter Property="Control.Template">
                                <Setter.Value>
                                  <ControlTemplate TargetType="ToggleButton">
                                    <Border Height="16" Width="16" Background="#00FFFFFF" Padding="5,5,5,5">
                                      <Path Fill="#00FFFFFF" Name="ExpandPath" Stroke="#FF989898">
                                        <Path.Data>
                                          <PathGeometry Figures="M0,0L0,6L6,0z" />
                                        </Path.Data>
                                        <Path.RenderTransform>
                                          <RotateTransform CenterX="3" Angle="135" CenterY="3" />
                                        </Path.RenderTransform>
                                      </Path>
                                    </Border>
                                    <ControlTemplate.Triggers>
                                      <Trigger Property="UIElement.IsMouseOver">
                                        <Setter Property="Shape.Stroke" TargetName="ExpandPath">
                                          <Setter.Value>
                                            <SolidColorBrush>#FF1BBBFA</SolidColorBrush>
                                          </Setter.Value>
                                        </Setter>
                                        <Setter Property="Shape.Fill" TargetName="ExpandPath">
                                          <Setter.Value>
                                            <SolidColorBrush>#00FFFFFF</SolidColorBrush>
                                          </Setter.Value>
                                        </Setter>
                                        <Trigger.Value>
                                          <s:Boolean>True</s:Boolean>
                                        </Trigger.Value>
                                      </Trigger>
                                      <Trigger Property="ToggleButton.IsChecked">
                                        <Setter Property="UIElement.RenderTransform" TargetName="ExpandPath">
                                          <Setter.Value>
                                            <RotateTransform CenterX="3" Angle="180" CenterY="3" />
                                          </Setter.Value>
                                        </Setter>
                                        <Setter Property="Shape.Fill" TargetName="ExpandPath">
                                          <Setter.Value>
                                            <SolidColorBrush>#FF595959</SolidColorBrush>
                                          </Setter.Value>
                                        </Setter>
                                        <Setter Property="Shape.Stroke" TargetName="ExpandPath">
                                          <Setter.Value>
                                            <SolidColorBrush>#FF262626</SolidColorBrush>
                                          </Setter.Value>
                                        </Setter>
                                        <Trigger.Value>
                                          <s:Boolean>True</s:Boolean>
                                        </Trigger.Value>
                                      </Trigger>
                                    </ControlTemplate.Triggers>
                                  </ControlTemplate>
                                </Setter.Value>
                              </Setter>
                            </Style>
                          </ToggleButton.Style>
                        </ToggleButton>
                      </Grid>
                    </r:TreeGridViewRowPresenter.Expander>
                  </r:TreeGridViewRowPresenter>
                </Grid>
              </Border>
            </Border>

            <ItemsPresenter Grid.Row="1" Name="ItemsHost" />
          </Grid>
          <ControlTemplate.Triggers>
            <Trigger Property="TreeViewItem.IsExpanded">
              <Setter Property="UIElement.Visibility" TargetName="ItemsHost" Value="{x:Static Visibility.Collapsed}" />
              <Trigger.Value>
                <s:Boolean>False</s:Boolean>
              </Trigger.Value>
            </Trigger>
            <Trigger Property="ItemsControl.HasItems">
              <Setter Property="UIElement.Visibility" TargetName="Expander" Value="{x:Static Visibility.Hidden}" />
              <Trigger.Value>
                <s:Boolean>False</s:Boolean>
              </Trigger.Value>
            </Trigger>

            <Trigger Property="UIElement.IsMouseOver" SourceName="item">
              <Setter Property="Panel.Background" TargetName="item">
                <Setter.Value>
                  <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                    <LinearGradientBrush.GradientStops>
                      <GradientStop Offset="0" Color="#FFF1FBFF" />
                      <GradientStop Offset="1" Color="#FFD5F1FE" />
                    </LinearGradientBrush.GradientStops>
                  </LinearGradientBrush>
                </Setter.Value>
              </Setter>
              <Setter Property="Border.BorderBrush" TargetName="item">
                <Setter.Value>
                  <SolidColorBrush>#FFCCF0FF</SolidColorBrush>
                </Setter.Value>
              </Setter>
              <Setter Property="UIElement.Visibility" TargetName="UpperHighlight" Value="{x:Static Visibility.Visible}" />
              <Trigger.Value>
                <s:Boolean>True</s:Boolean>
              </Trigger.Value>
            </Trigger>
            <Trigger Property="TreeViewItem.IsSelected">
              <Setter Property="Panel.Background" TargetName="item">
                <Setter.Value>
                  <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                    <LinearGradientBrush.GradientStops>
                      <GradientStop Offset="0" Color="#FFD9F4FF" />
                      <GradientStop Offset="1" Color="#FF9BDDFB" />
                    </LinearGradientBrush.GradientStops>
                  </LinearGradientBrush>
                </Setter.Value>
              </Setter>
              <Setter Property="Border.BorderBrush" TargetName="item">
                <Setter.Value>
                  <SolidColorBrush>#FF98DDFB</SolidColorBrush>
                </Setter.Value>
              </Setter>
              <Setter Property="Border.BorderBrush" TargetName="InnerBorder">
                <Setter.Value>
                  <SolidColorBrush>#80FFFFFF</SolidColorBrush>
                </Setter.Value>
              </Setter>
              <Setter Property="UIElement.Visibility" TargetName="UpperHighlight" Value="{x:Static Visibility.Visible}" />
              <Setter Property="Shape.Fill" TargetName="UpperHighlight">
                <Setter.Value>
                  <SolidColorBrush>#40FFFFFF</SolidColorBrush>
                </Setter.Value>
              </Setter>
              <Trigger.Value>
                <s:Boolean>True</s:Boolean>
              </Trigger.Value>
            </Trigger>
            <MultiTrigger>
              <MultiTrigger.Conditions>
                <Condition Property="TreeViewItem.IsSelected">
                  <Condition.Value>
                    <s:Boolean>True</s:Boolean>
                  </Condition.Value>
                </Condition>
                <Condition Property="TreeViewItem.IsSelectionActive">
                  <Condition.Value>
                    <s:Boolean>False</s:Boolean>
                  </Condition.Value>
                </Condition>
              </MultiTrigger.Conditions>
              <Setter Property="Panel.Background" TargetName="item">
                <Setter.Value>
                  <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                    <LinearGradientBrush.GradientStops>
                      <GradientStop Offset="0" Color="#FFEEEDED" />
                      <GradientStop Offset="1" Color="#FFDDDDDD" />
                    </LinearGradientBrush.GradientStops>
                  </LinearGradientBrush>
                </Setter.Value>
              </Setter>
              <Setter Property="Border.BorderBrush" TargetName="item">
                <Setter.Value>
                  <SolidColorBrush>#FFCFCFCF</SolidColorBrush>
                </Setter.Value>
              </Setter>
            </MultiTrigger>
            <MultiTrigger>
              <MultiTrigger.Conditions>
                <Condition Property="IsSelected">
                  <Condition.Value>
                    <s:Boolean>True</s:Boolean>
                  </Condition.Value>
                </Condition>
                <Condition Property="UIElement.IsMouseOver">
                  <Condition.Value>
                    <s:Boolean>True</s:Boolean>
                  </Condition.Value>
                </Condition>
              </MultiTrigger.Conditions>
              <Setter Property="Panel.Background" TargetName="item">
                <Setter.Value>
                  <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                    <LinearGradientBrush.GradientStops>
                      <GradientStop Offset="0" Color="#FFEAF9FF" />
                      <GradientStop Offset="1" Color="#FFC9EDFD" />
                    </LinearGradientBrush.GradientStops>
                  </LinearGradientBrush>
                </Setter.Value>
              </Setter>
              <Setter Property="Border.BorderBrush" TargetName="item">
                <Setter.Value>
                  <SolidColorBrush>#FF98DDFB</SolidColorBrush>
                </Setter.Value>
              </Setter>
            </MultiTrigger>
            <Trigger Property="UIElement.IsEnabled">
              <Setter Property="TextElement.Foreground" TargetName="item">
                <Setter.Value>
                  <DynamicResource ResourceKey="{x:Static SystemColors.GrayTextBrushKey}" />
                </Setter.Value>
              </Setter>
              <Trigger.Value>
                <s:Boolean>False</s:Boolean>
              </Trigger.Value>
            </Trigger>
          </ControlTemplate.Triggers>

        </ControlTemplate>
      </Setter.Value>
    </Setter>

  </Style>
  
  <Style x:Key="scroll">
    <Setter Property="UIElement.Focusable">
      <Setter.Value>
        <s:Boolean>False</s:Boolean>
      </Setter.Value>
    </Setter>
    <Setter Property="Control.Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ScrollViewer}">
          <Grid Background="{TemplateBinding Background}"
                SnapsToDevicePixels="true">
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="*"/>
              <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
              <RowDefinition Height="*"/>
              <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <DockPanel Margin="{TemplateBinding Padding}">
              <ScrollViewer DockPanel.Dock="Top"
                            HorizontalScrollBarVisibility="Hidden"
                            VerticalScrollBarVisibility="Hidden"
                            Focusable="false">

                <!--ColumnHeaderContainerStyle="{Binding Path=TemplatedParent.View.ColumnHeaderContainerStyle,RelativeSource={RelativeSource TemplatedParent}}"
                                            ColumnHeaderTemplate="{Binding Path=TemplatedParent.View.ColumnHeaderTemplate,RelativeSource={RelativeSource TemplatedParent}}"
                                            ColumnHeaderTemplateSelector="{Binding Path=TemplatedParent.View.ColumnHeaderTemplateSelector,RelativeSource={RelativeSource TemplatedParent}}"
                                            AllowsColumnReorder="{Binding Path=TemplatedParent.View.AllowsColumnReorder,RelativeSource={RelativeSource TemplatedParent}}"
                                            ColumnHeaderContextMenu="{Binding Path=TemplatedParent.View.ColumnHeaderContextMenu,RelativeSource={RelativeSource TemplatedParent}}"
                                            ColumnHeaderToolTip="{Binding Path=TemplatedParent.View.ColumnHeaderToolTip,RelativeSource={RelativeSource TemplatedParent}}"-->
                <GridViewHeaderRowPresenter Margin="2,0,2,0"
                                            Columns="{Binding Path=Columns,RelativeSource={RelativeSource AncestorType={x:Type r:TreeListView}}}"
                                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
              </ScrollViewer>
              <ScrollContentPresenter Name="PART_ScrollContentPresenter"
                                      KeyboardNavigation.DirectionalNavigation="Local"
                                      Content="{TemplateBinding Content}"
                                      ContentTemplate="{TemplateBinding ContentTemplate}"
                                      CanContentScroll="{TemplateBinding CanContentScroll}"
                                      SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
            </DockPanel>
            <ScrollBar Name="PART_HorizontalScrollBar"
                       Orientation="Horizontal"
                       Grid.Row="1"
                       Minimum="0.0"
                       Maximum="{TemplateBinding ScrollableWidth}"
                       ViewportSize="{TemplateBinding ViewportWidth}"
                       Value="{Binding Path=HorizontalOffset,RelativeSource={RelativeSource TemplatedParent},Mode=OneWay}"
                       Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"
                       Cursor="Arrow"/>
            <ScrollBar Name="PART_VerticalScrollBar"
                       Orientation="Vertical"
                       Grid.Column="1"
                       Minimum="0.0"
                       Maximum="{TemplateBinding ScrollableHeight}"
                       ViewportSize="{TemplateBinding ViewportHeight}"
                       Value="{Binding Path=VerticalOffset,RelativeSource={RelativeSource TemplatedParent},Mode=OneWay}"
                       Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
                       Cursor="Arrow"/>
            <DockPanel Grid.Column="1"
                       Grid.Row="1"
                       Background="{Binding Path=Background,ElementName=PART_VerticalScrollBar}"
                       LastChildFill="false">
              <Rectangle DockPanel.Dock="Left"
                         Width="1"
                         Fill="White"
                         Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/>
              <Rectangle DockPanel.Dock="Top"
                         Height="1"
                         Fill="White"
                         Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>
            </DockPanel>
          </Grid>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style TargetType="{x:Type r:TreeListView}">

    <Setter Property="Panel.Background">
      <Setter.Value>
        <DynamicResource ResourceKey="{x:Static SystemColors.WindowBrushKey}" />
      </Setter.Value>
    </Setter>
    <Setter Property="Border.BorderBrush">
      <Setter.Value>
        <SolidColorBrush>#FF828790</SolidColorBrush>
      </Setter.Value>
    </Setter>
    <Setter Property="Border.BorderThickness">
      <Setter.Value>
        <Thickness>1,1,1,1</Thickness>
      </Setter.Value>
    </Setter>
    <Setter Property="TextElement.Foreground">
      <Setter.Value>
        <SolidColorBrush>#FF042271</SolidColorBrush>
      </Setter.Value>
    </Setter>
    <Setter Property="ScrollViewer.HorizontalScrollBarVisibility">
      <Setter.Value>
        <x:Static Member="ScrollBarVisibility.Auto" />
      </Setter.Value>
    </Setter>
    <Setter Property="ScrollViewer.VerticalScrollBarVisibility">
      <Setter.Value>
        <x:Static Member="ScrollBarVisibility.Auto" />
      </Setter.Value>
    </Setter>
    <Setter Property="ScrollViewer.CanContentScroll">
      <Setter.Value>
        <s:Boolean>True</s:Boolean>
      </Setter.Value>
    </Setter>
    <Setter Property="Control.VerticalContentAlignment">
      <Setter.Value>
        <x:Static Member="VerticalAlignment.Center" />
      </Setter.Value>
    </Setter>
    <Setter Property="Control.Template">
      <Setter.Value>
        <!-- Style="{StaticResource scroll}"-->
        <ControlTemplate TargetType="r:TreeListView">
          <mwt:ListBoxChrome BorderBrush="{TemplateBinding Border.BorderBrush}" RenderMouseOver="{TemplateBinding UIElement.IsMouseOver}" BorderThickness="{TemplateBinding Border.BorderThickness}" Name="Bd" Background="{TemplateBinding Panel.Background}" SnapsToDevicePixels="True" RenderFocused="{TemplateBinding UIElement.IsKeyboardFocusWithin}">
            <ScrollViewer Style="{StaticResource scroll}" Background="{TemplateBinding Background}"
                          Focusable="false"
                          CanContentScroll="false"
                          HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
                          VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
                          Padding="{TemplateBinding Padding}"
                          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
              <ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
            </ScrollViewer>
          </mwt:ListBoxChrome>
          <ControlTemplate.Triggers>
            <Trigger Property="UIElement.IsEnabled">
              <Setter Property="Panel.Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
              <Trigger.Value>
                <s:Boolean>False</s:Boolean>
              </Trigger.Value>
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>

  </Style>

</ResourceDictionary>